/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Dao;

import Interface.InterfaceEmployee;
import Pojo.Employees;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author knyazev_o
 */
public class DaoEmployee implements InterfaceEmployee{

    @Override
    public boolean register(Session session, Employees employees) throws Exception {
        session.save(employees);        
        return true;
    }

    @Override
    public List<Employees> getAll(Session session) throws Exception {
        String hql="from Employees";
        Query query=session.createQuery(hql);        
        List<Employees> listEmployees =(List<Employees>) query.list();        
        return listEmployees;
    }

    @Override
    public Employees getByIdEmployee(Session session, Long id) throws Exception {
        return (Employees) session.get(Employees.class, id);
    }

    @Override
    public Employees getByLogin(Session session, String login) throws Exception {
        String hql="from Employees where login=:login";
        Query query=session.createQuery(hql);
        query.setParameter("login", login);        
        Employees employees=(Employees) query.uniqueResult();        
        return employees;
    }

    @Override
    public Employees getByLoginDiferent(Session session, Long id, String login) throws Exception {
        String hql="from Employees where id!=:id and login=:login";
        Query query=session.createQuery(hql);
        query.setParameter("id", id);
        query.setParameter("login", login);        
        Employees employees=(Employees) query.uniqueResult();        
        return employees;
    }

    @Override
    public boolean update(Session session, Employees employees) throws Exception {
        session.update(employees);
        return true;
    }

    
}
